const querystring = require('querystring');
const CryptoJS = require("crypto-js")


const sF = "zxcvbnmlkjhgfdsaqwertyuiop0987654321QWERTYUIOPLKJHGFDSAZXCVBNM"

function sha256(input) {
    return CryptoJS.SHA256(input).toString()
}

function cne(e) {
    return [...Array(e)].map(() => sF[ane(0, 61)]).join("")
}

function ane(e, t) {
    switch (arguments.length) {
        case 1:
            return parseInt(Math.random() * e + 1, 10);
        case 2:
            return parseInt(Math.random() * (t - e + 1) + e, 10);
        default:
            return 0
    }
}

var a = Date.now()
var l = cne(16)

function objectToQueryString(obj) {
    const orderedKeys = [
        "keyword", "openConvert", "pageNo", "pageSize",
        "projectType", "publishEndTime", "publishStartTime",
        "secondType", "siteCode", "thirdType",
        "tradingProcess", "type"
    ];

    const parts = [];

    for (const key of orderedKeys) {
        if (obj.hasOwnProperty(key)) {
            const value = obj[key];

            if (value !== undefined) {
                const encodedKey = encodeURIComponent(key);
                const encodedValue = encodeURIComponent(value);
                parts.push(`${encodedKey}=${encodedValue}`);
            }
        }
    }

    return parts.join('&');
}


function result(page) {
    var a = Date.now();
    var l = cne(16)
    o = {
        "type": "trading-type",
        "openConvert": false,
        "keyword": "",
        "siteCode": "44",
        "secondType": "A",
        "tradingProcess": "",
        "thirdType": "[]",
        "projectType": "",
        "publishStartTime": "",
        "publishEndTime": "",
        "pageNo": page,
        "pageSize": 10
    }
    r_2 = objectToQueryString(o)
    console.log(".....r2", r_2)
    var p_2 = sha256(l + "k8tUyS$m" + decodeURIComponent(r_2) + a).toString()
    console.log(p_2)
    return {
        "X-Dgi-Req-Nonce":l,
        "X-Dgi-Req-Signature":p_2,
        "X-Dgi-Req-Timestamp":a
    }
}


console.log(result(2))